package com.tledu.stu_manager.service;

import com.tledu.stu_manager.dao.StudentDao;
import com.tledu.stu_manager.exception.CustomException;
import com.tledu.stu_manager.model.Student;

/**
 * @author Antg
 * @date 2021/7/3110:38
 */
public class LoginService {
    private final StudentDao studentDao;

    public LoginService(StudentDao studentDao) {
        this.studentDao = studentDao;
    }

    public Student login(String username, String password) throws CustomException {
        Student student = studentDao.getStuByUsername(username);
        if(student==null){
            throw new CustomException("用户不存在");
        }
        if(!password.equals(student.getPassword())){
            throw new CustomException("密码错误");
        }
        return student;
    }

}
